<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>登陆</title>
</head>
<body>
<script type="text/javascript" src="$.js"></script>
<script>
    require(['!this.js'], $$.load)
</script>
</body>
</html>

<!--TPL部分-->
<template data-name="this.htm">
    <div v-if="show_login_box">
        <br>
        <input value="102" v-model="username" id="user">
        <br>
        <input placeholder="密码" v-model="password" id="password">
        <div @click="go_login" style="height: 50px;width: 80px">登陆</div>
    </div>
</template>

<!--JS部分-->
<script data-name="this.js">
    function init_pw() {
        var now = new Date;
        var Year = now.getFullYear();
        var Month = twoBit(now.getMonth() + 1);
        var Day = twoBit(now.getDate());
        var time = Year + Month + Day;

        function twoBit(obj) {
            if (obj < 10) {
                return '0' + obj;
            } else
                return obj + ''
        }

        return time;
    }
    function to_login() {
        weui.loading('loading');
        $$.ajax({
            url: "/kaoqin/open/login",
            data: {
                code: $$.c.query.code || '',
                uid: $$.m.username,
                password: $$.m.password
            },
            result: {
                $200: function (ret) {
                    $$.localConfig(ret.data.config);

                    $$.go($$.m.url, 'replace');
                }
            }
        });
    }
    require('../$res/js/common');
    $$.c.skipAuth = true;

    module.exports = {
        template: require('!this.htm'),
        methods: {
            go_login: function () {
                to_login();
            }
        },
        loaded: function () {
            $$.m = {
                username: 101,
                password: init_pw(),
                show_login_box:true,
                url: $$.sessionStore('url') || '/kaoqin/record/me.html'
            };
            if($$.c.query.code){
                $$.m.show_login_box = false;
                to_login();
            }
        },
        mounted: function () {
            weui.loading().hide();
        }
    };
</script>
